<template>
  <div class="header-container">
    <div class="l-content">
      <el-button
        @click="handleMenu"
        icon="el-icon-menu"
        size="mini"
      ></el-button>
      <!-- 面包屑 -->
      <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="item in list" :key="item.name"
          >{{ item.label }}
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="r-content">
      <el-dropdown @command="handleClick">
        <span class="el-dropdown-link">
          <img class="user" src="../assets/images/user.jpg" alt="" />
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command="info">个人信息</el-dropdown-item>
          <el-dropdown-item>
              <el-popconfirm
                      @confirm="exit"
                      confirm-button-text='退出'
                      cancel-button-text='取消'
                      title="确定退出么?">
                  <div slot="reference">退出</div>
              </el-popconfirm>
          </el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  methods: {
    handleMenu() {
      // 相当于调用这个方法 tabjs找
      this.$store.commit("CollapseMenu");
    },
    handleClick(command) {
      if (command === "logout") {
        this.$router.push("/login");
        this.$store.commit("goBackTabList"); // 清楚路由列表
        return;
      }
      if (command === "info") {
        this.$router.push("/info");
      }
    },
      exit() {
          this.$router.push("/login");
          this.$store.commit("goBackTabList"); // 清楚路由列表
      },
  },
  computed: {
    ...mapState({
      // 从tabjs取数据
      tags: (state) => state.tab.tabList,
      menus: (state) => state.tab.menu,
    }),
    list() {
      for (let i = 0; i < this.menus.length; i++) {
        if (this.menus[i].name === this.$route.name) {
          return [this.menus[i]];
        }
      }
      return "";
    },
  },
};
</script>

<style lang="less" scoped>
.header-container {
  background-color: #333;
  height: 60px;

  // 让按钮和头像居中
  display: flex;
  justify-content: space-between;
  align-items: center;
  // 不要紧贴边框
  padding: 0 20px;

  .el-dropdown-link {
    cursor: pointer;
    color: #409eff;

    .user {
      width: 40px;
      height: 40px;
      // 50%变圆形
      border-radius: 50%;
    }
  }
}

.l-content {
  display: flex;
  // 上下居中
  align-items: center;

  .el-breadcrumb {
    margin-left: 15px;

    // deep 强制生效
    /deep/.el-breadcrumb__item {
      .el-breadcrumb__inner {
        &.is-link {
          color: #666;
        }
      }

      &:last-child {
        .el-breadcrumb__inner {
          color: #fff;
        }
      }
    }
  }
}
</style>
